package demo;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-03-27
 * Time: 20:11
 */
public class Cardfunc {
    public static final String[] suits = {"♥", "♠", "♣", "♦"};

    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        for (int i = 1; i < 13; i++) {
            for (int j = 0; j < 4; j++) {
                int rank = i;
                String suit = suits[j];
                Card card = new Card(suit, rank);
                cardList.add(card);
            }
        }
        return cardList;
    }

    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size() - 1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cardList, i, index);
        }
    }

    private void swap(List<Card> cardlist, int i, int j) {
        Card tmp = cardlist.get(i);
        cardlist.set(i, cardlist.get(j));
        cardlist.set(j, tmp);

    }

    public List<List<Card>> play(List<Card> cardList) {
        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();

        List<List<Card>> hand = new ArrayList<>();
        hand.add(hand0);
        hand.add(hand1);
        hand.add(hand2);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }
}